﻿using UnityEngine;
using System.Collections;

public class BattlefieldFriendCheckBox : ObjectBase
{
	BattlefieldFriendScene sceneManager = null;

	string m_Sound = "UI_check_box";

	Transform m_On;
	Transform m_Off;
	Transform m_Disable;
	
	public bool IsChecked
	{
		get { return m_IsChecked; }
		set 
		{ 
			m_IsChecked = value;
			SetState();
		}
	}
	bool m_IsChecked = false;   
	
	public bool isEnabled 
	{ 
		get
		{
			return enabled; 
		} 
		set
		{
			enabled = value;
			SetDisable();
		} 
	}
	
	void Awake()
	{
		m_On = transform.Find("on");
		m_Off = transform.Find("off");       
		m_Disable = transform.Find("disable");
		
		SetState();
	}

	void Start()
	{
		sceneManager = GameObject.Find ("SceneManager").GetComponent<BattlefieldFriendScene>();
		sceneManager.battlefieldFriendCheckBoxList.Add(this);
	}
	
	void OnPress(bool isPressed)
	{
		if (isPressed)
		{
			
		}
		else
		{
			sceneManager.UncheckedOthers(this);
			IsChecked = !IsChecked;
			SoundController.PlaySound(m_Sound);
		}
	}
	
	void SetDisable()
	{
		if (m_Disable != null)
			NGUITools.SetActive(m_Disable.gameObject, !isEnabled);
		if (m_On != null)
			NGUITools.SetActive(m_On.gameObject, isEnabled);
		if (m_Off != null)
			NGUITools.SetActive(m_Off.gameObject, isEnabled);
	}
	
	protected virtual void SetState()
	{
		NGUITools.SetActive(m_Off.gameObject, !IsChecked);
		NGUITools.SetActive(m_On.gameObject, IsChecked);
	}
	
}
